package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.pro.constant.SymbolConstant;
import java.util.List;
import lombok.Getter;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/3/28 21:08
 * @since v1.0
 */
@Getter
public enum RelatedPersonnelEnum {

    /**
     * 高级可见选项-相关人员
     */
    OWNER(1, "enum.relatedPersonnel.memo.owner"),

    CO_USER(2, "enum.relatedPersonnel.memo.co_user"),

    CREATOR(3, "enum.relatedPersonnel.memo.creator"),

    OWNER_SUP(4, "enum.relatedPersonnel.memo.owner_sup"),;

    private Integer type;

    private String memo;

    RelatedPersonnelEnum(Integer type, String memo) {
        this.type = type;
        this.memo = memo;
    }

    public static RelatedPersonnelEnum getByType(Integer type) {
        for (RelatedPersonnelEnum relatedPersonnelEnum :values()) {
            if (relatedPersonnelEnum.getType().equals(type)) {
                return relatedPersonnelEnum;
            }
        }
        return null;
    }

    /**
     * 拼接相关人员，用逗号相隔，如“负责人,协同人”
     * @param relative 相关人员对应type
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/11 20:46
     * @since v1.0
     * @version v1.0
     */
    public static String getRelatives(List<Integer> relative){
        if (relative == null || relative.size() == 0) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        for (RelatedPersonnelEnum cache :values()) {
            if (relative.contains(cache.type)) {
                sb.append(cache.getMemo()).append(SymbolConstant.COMMA_ENGLISH);
            }
        }
        String relatives = sb.deleteCharAt(sb.length() - 1).toString();
        return relatives;
    }

    public String getMemo() {
        return I18nMessageUtil.getMessage(memo);
    }
}
